#ifndef TCP_SERVER_H
#define TCP_SERVER_H

typedef int (*connection_completed_callback_t)(struct tcp_connection *conn);
typedef int (*message_callback_t)(struct buffer *buf, struct tcp_connection *conn);
typedef int (*write_completed_callback_t)(struct tcp_connection *conn);
typedef int (*connection_closed_callback_t)(struct tcp_connection *conn);

#include "tcp_connection.h"
#include "acceptor.h"

struct TCPServer
{
    int port;
    struct event_loop *eloop;
    struct acceptor *acceptor;
    connection_completed_callback_t connection_completed_callback;
    message_callback_t message_callback;
    write_completed_callback_t write_completed_callback;
    connection_closed_callback_t connection_closed_callback;
    int thread_num;
    struct thread_pool *pool;
    void *data;
};

struct TCPServer *tcp_server_init(struct event_loop *eloop, struct acceptor *acceptor,
                                  connection_completed_callback_t connection_completed_callback,
                                  message_callback_t message_callback,
                                  write_completed_callback_t write_completed_callback,
                                  connection_closed_callback_t connection_closed_callback,
                                  int thread_num);

void tcp_server_start(struct TCPServer *server);

void tcp_server_set_data(struct TCPServer *server, void *data);

#endif